﻿@{
    ViewBag.Title = "流程定义列表";
    Layout = "~/Views/Shared/_Base.cshtml";
}

@section head{
    <script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.validate.min.js")"></script>
    <script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.metadata.js")"></script>
    <script src="@Url.Content("~/Content/roohui/jquery-validation/messages_cn.js")"></script> 
    <script src="@Url.Content("~/Content/operate/processdefmanage.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var proData =
         [{ id: 1, text: '项目流程' },
         { id: 2, text: '其他流程'}];
            selType = $("#selType").ligerComboBox({
                width: 300,
                data: proData,
                cancelable: true, isMultiSelect: false
            });
        });
    </script>
}
<div id="toptoolbar" style="width: 100%">
</div> 
<div id="processdefgrid">
</div>

<form action="/" method="post" id="frmProcessDef" name="frmProcessDef" style="background-color: white;
display: none">
    <table cellpadding="0" cellspacing="0" class="l-table-edit" width="100%">
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;流程名称:
            </td>
            <td align="left" class="l-table-edit-td" >
             
                <input name="txtProcessDefName" type="text" id="txtProcessDefName" ligerui="width:300" style="width:300"   validate="{required:true}"/>
               
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;流程类型:
            </td>
            <td align="left" class="l-table-edit-td">
                  <select id="selType" name="selType">
                    <option  value="1">项目流程</option>
                    <option  value="2">其他流程</option>
                </select>
            </td>
            <td align="left">
            </td>
        </tr>
         
        <tr>
        <td align="center" colspan="3">
            <span id="lblmsg" class="l-validate-error">&nbsp;</span>
            <input type="hidden" name="processdefID" id="processdefID" value="0" />
        </td>
    </tr>
    </table>
</form>
<script type="text/javascript">
    var processdefgrid;
    var saveDialog;
    var selType;
    $(function () {
        //selType = $("#selType").ligerComboBox();
       
        $("#toptoolbar").ligerToolBar({ items: [{ text: '新增', click: grid_processDef_add, icon: "add" },
            { text: '修改', click: grid_processDef_edit, icon: "modify" },
            { text: '删除', click: grid_processDef_delete, icon: "delete" },
            { text: '刷新', click: grid_processDef_refresh, icon: "refresh" }
            ]
        });
        processdefgrid = $("#processdefgrid").ligerGrid({
            columns: [
                { display: '名称', name: 'ProcessDefName', width: '50%', isSort: false },
                { display: '类型', name: 'ProcessType', width: '10%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.ProcessType) == 1) return '项目流程';
                        return '其他流程';
                    }
                },

                { display: '状态', name: 'Status', width: '10%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.Status) == 1) return '正常';
                        return '禁用';
                    }
                },
                {
                    display: '操作', isAllowHide: false,
                    render: function (row) {

                        var html = '<a href="#" onclick="grid_processDef_show(\'' + row.ID + '\',\'' + row.ProcessDefName + '\',\'' + row.ProcessType + '\')">修改</a>&nbsp;&nbsp;<a href="#" onclick="processDef_delete(\'' + row.ID + '\',\'' + row.ProcessDefName + '\')">删除</a>';
                        if (row.Status == 1) {
                            html = html + '&nbsp;&nbsp;<a href="#" onclick="changestate(\'' + row.ID + '\',0,\'' + row.ProcessDefName + '\')">禁用</a>';
                        }
                        else {
                            html = html + '&nbsp;&nbsp;<a href="#" onclick="changestate(\'' + row.ID + '\',1,\'' + row.ProcessDefName + '\')">启用</a>';
                        }
                        html = html + '&nbsp;&nbsp;<a href="#" onclick="openProcess(\'' + row.ID + '\',\'' + row.ProcessType + '\')">流程节点</a>';
                        html = html + '&nbsp;&nbsp;<a href="#" onclick="openProcessStep(\'' + row.ID + '\',\'' + row.ProcessType + '\')">逻辑条件</a>';
                        return html;
                    }
                }
                ],
            width: '100%', height: '100%', rownumbers: true,
            dataAction: 'server',
            url: "/Process/GetProcessDefListByPage",
            pageSizeOptions: [10],
            pageSize: 10
        });

        $.metadata.setType("attr", "validate");
        var v = $("#frmProcessDef").validate({
            //debug: true,
            errorPlacement: function (lable, element) {
                if (element.hasClass("l-textarea")) {
                    element.ligerTip({ content: lable.html(), target: element[0] });
                }
                else if (element.hasClass("l-text-field")) {
                    element.parent().ligerTip({ content: lable.html(), target: element[0] });
                }
                else {
                    lable.appendTo(element.parents("td:first").next("td"));
                }
            },
            success: function (lable) {
                lable.ligerHideTip();
                lable.remove();
            },
            submitHandler: function () {
                if ($('#txtProcessDefName').val() == "") {
                    $('#txtProcessDefName').focus();
                    $("#lblmsg").html('流程名称不能为空');
                    return;
                }
                $.ajax({
                    url: "/Process/ProcessDefSave",
                    data: "processDefName=" + $('#txtProcessDefName').val() + "&processDefType=" + selType.getValue()
                    + "&defID=" + $("#processdefID").val(),
                    type: "post",
                    success: function (result) {
                        //写提交ajax操作
                        if (result == "1") {
                            $.ligerDialog.success("保存成功。");
                            processDef_reset();
                            saveDialog.hide();
                            grid_processDef_refresh();
                        }
                        else {
                            if (result == "-1") {
                                $.ligerDialog.error("流程名已存在!");
                            }
                            else {
                                $.ligerDialog.error("保存失败。");
                            }
                        }

                    }
                });
            }
        });
        $("#frmProcessDef").ligerForm();

    });
    function openProcess(defID, type) {
        location.href = decodeURIComponent("/Process/ProcessProcList?defID=" + defID + "&processDefType=" + type);
    }
    function openProcessStep(defID, type) {
        location.href = decodeURIComponent("/Process/ProcessStepList?defID=" + defID + "&processDefType=" + type);
    }
</script>
